<template>
  <div>
    <!-- 联系人 -->
    <div class="honor bg-ff">
      <div class="contact">
        <div
          class="contact_li flex align-center text-content"
          v-for="(item, index) in list"
          :key="index"
        >
          <img class="radius-50p margin-r15" v-if="item.head_img" :src="item.head_img" alt />
          <img
            class="radius-50p margin-r15"
            v-if="!item.head_img"
            src="@/assets/img/nologin.png"
            alt
          />
          <div class="flex-grow">
            <div>
              <span class="rem-30px">{{item.user_name}}</span>&emsp;
              <span class="c-99 rem-24px">{{item.position_name}}</span>
            </div>
            <div class="rem-20px">{{item.user_phone}}</div>
          </div>
          <div class="contact_icon" @click="getAplly(item.friendSta,item.link_id)">
            <i v-if="item.friendSta == 2" class="iconfont icon-jiahaoyou"></i>
            <a v-if="item.friendSta == 1" :href="'tel:' + item.user_phone">
              <i class="iconfont icon-boda"></i>
            </a>
            <i v-if="item.friendSta == -1" class="iconfont icon-gengxin"></i>
            <i v-if="item.friendSta == 0" class="iconfont icon-shijian"></i>
          </div>
        </div>
      </div>
    </div>
    <load @loadData="getLink" :list="list" :total="total"></load>
  </div>
</template>

<script>
import load from "../components/load";
export default {
  components: {
    load
  },
  data() {
    return {
      list: [],
      total: 0
    };
  },
  mounted() {
    document.querySelector("html").style.backgroundColor = "#ffffff";
    this.getLink(1);
  },
  methods: {
    // 联系人
    getLink(page) {
      this.$axios
        .post("/wap/info/link", {
          token: localStorage.getItem("token"),
          enterprise_id: this.$route.query.id,
          page: page,
          limit: 10
        })
        .then(res => {
          if (page == 1) {
            this.list = [];
            this.topList = [];
          }
          if (res.data.data.length == 0) {
            this.total++;
            return false;
          }
          for (let i in res.data.data) {
            this.list.push(res.data.data[i]);
          }
        });
    },
    // 好友申请
    getAplly(type, id) {
      let token = localStorage.getItem("token");
      if (!token) {
        // 登录成功后跳转地址
        localStorage.setItem('returnPath', window.location.href)
        
        this.$toast("请登录个人账户进行操作");
        this.$router.push({
          path: "/recruit/login",
          query: {
            type: "card"
          }
        });
        return false;
      }
      if (type == 2 || type == -1) {
        this.$axios
          .post("/wap/handle/friend", {
            token: token,
            type: type == 2 ? 1 : 2,
            link_id: id
          })
          .then(res => {
            this.$toast(res.data.msg);
            this.getLink(1);
          });
      }
    },
    to(path, id) {
      this.$router.push({
        path: path,
        query: {
          id: id
        }
      });
    }
  }
};
</script>

<style scoped>
.honor {
  padding: 0 0.2rem;
}

.honor_super {
  padding: 0.2rem 0;
  overflow-x: scroll;
}
.honor_ul {
  overflow: hidden;
}
.honor_li {
  float: left;
  margin-right: 0.2rem;
}

.honor .honor_li:last-of-type {
  margin-right: 0;
}

.honor_li img {
  width: 2.22rem;
  height: 1.38rem;
  display: block;
}

.contact_li {
  width: 100%;
  padding: 0.25rem 0;
}
.contact_icon {
  width: 0.72rem;
  height: 0.72rem;
  line-height: 0.72rem;
  border: 0.01rem solid #ffcccc;
  border-radius: 50%;
  text-align: center;
}

.contact_li img {
  width: 0.96rem;
  height: 0.96rem;
  display: block;
}
</style>
